package name.fowler.refactoring.simplestore.services;

import name.fowler.refactoring.simplestore.domain.Customer;
import name.fowler.refactoring.simplestore.domain.Rental;

import javax.faces.bean.ApplicationScoped;
import java.util.ArrayList;
import java.util.List;

/**
 * User: RedSmog
 * Date: 12.10.13
 * Time: 16:53
 */

@ApplicationScoped
public class ReportRentalMovies implements Report {
    @Override
    public String getReportTitle() {
        return "List of rented movies:\n";
    }

    @Override
    public String getReportFooter() {
        return "Total rented  movies: ";
    }

    @Override
    public String getCustomerFooter(Customer customer, Formatter formatter) {
        List<String> movieTitles = new ArrayList<String>(customer.getRentals().size());
        for (Rental each : customer.getRentals()) {
            movieTitles.add(each.getMovie().getTitle());
        }
        return formatter.printList(movieTitles);

    }

    @Override
    public String getCustomerHeader(Customer customer) {
        return "\t" + customer.getName() + ":";
    }

    @Override
    public String getTotal(List<Customer> customers) {
        int total =0;
        for (Customer customer : customers) {
            for (Rental rental : customer.getRentals()) {
                total++;
            }
        }
        return String.valueOf(total);
    }

    @Override
    public boolean isPrintDebitor(Customer customer) {
        return customer.getRentals().size() > 0;
    }
}
